<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>供应商管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
  <!-- 引入样式 -->
<link rel="stylesheet" href="/resources/layui/css/layui.css" media="all">
<link rel="stylesheet" href="/resources/css/public.css" media="all">
</head>
<body class="childrenBody">
<form class="layui-form" id="searchForm" method="post">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label" >供应商名称:</label>
            <div class="layui-input-inline">
                <input type="text" name="providername"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >供应商电话:</label>
            <div class="layui-input-inline">
                <input type="text" name="telephone" autocomplete="off" class="layui-input">
            </div>
        </div>
         <div class="layui-inline">
            <label class="layui-form-label" >联系人:</label>
            <div class="layui-input-inline">
                <input type="text" name="connectionperson" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
       <button type="button" class="layui-btn layui-btn-normal  layui-icon layui-icon-search" id="doSearch">查询</button>
	   <button type="reset" class="layui-btn layui-btn-warm  layui-icon layui-icon-refresh">重置</button>
    </div>
</form>
<table id="providerList" lay-filter="providerList"></table>
<!--表格工具条-->
<div  style="display: none;" id="tableToolBar">
	<a class="layui-btn layui-btn-sm" lay-event="add">添加</a>
</div>
<!--操作-->
<div   style="display: none;" id="providerListBar">
    <a class="layui-btn layui-btn-sm"  lay-event="update"  >修改</a>
    <a class="layui-btn layui-btn-sm layui-btn-danger"   lay-event="delete"  >删除</a>
</div>

<!-- 添加和修改开始 -->
<div id="dataFrmContent" style="padding: 10px;display: none;" >
	<form class="layui-form" method="post" id="dataFrm" lay-filter="dataFrm" >
		<div class="layui-form-item">
	        <div class="layui-inline">
	            <label class="layui-form-label" >供应商名称:</label>
	            <div class="layui-input-inline">
	            	<input type="hidden" name="id">
	                <input type="text" name="providername" placeholder="请输入供应商名称"  lay-verify="required"  autocomplete="off" class="layui-input">
	            </div>
	        </div>
	        <div class="layui-inline">
	            <label class="layui-form-label" >供应商电话:</label>
	            <div class="layui-input-inline">
	                <input type="text" name="telephone" placeholder="请输入供应商电话" lay-verify="required" autocomplete="off" class="layui-input">
	            </div>
	        </div>
	         <div class="layui-inline">
	            <label class="layui-form-label" >邮编:</label>
	            <div class="layui-input-inline">
	                <input type="text" name="zip" placeholder="请输入邮编" autocomplete="off" class="layui-input">
	            </div>
	        </div>
    	</div>
    	 <div class="layui-form-item">
		    <label class="layui-form-label">供应商地址</label>
		    <div class="layui-input-block">
		      <input type="text" name="address"  placeholder="请输入供应商地址" lay-verify="required" autocomplete="off"  class="layui-input">
		    </div>
		</div>
		<div class="layui-form-item">
	        <div class="layui-inline">
	            <label class="layui-form-label" >联系人:</label>
	            <div class="layui-input-inline">
	                <input type="text" name="connectionperson"  placeholder="请输入供应商联系人" lay-verify="required"  autocomplete="off" class="layui-input">
	            </div>
	        </div>
	        <div class="layui-inline">
	            <label class="layui-form-label" >联系电话:</label>
	            <div class="layui-input-inline">
	                <input type="text" name="phone" lay-verify="required" placeholder="请输入供应商联系人电话" autocomplete="off" class="layui-input">
	            </div>
	        </div>
	         <div class="layui-inline">
	            <label class="layui-form-label" >邮箱:</label>
	            <div class="layui-input-inline">
	                <input type="text" name="email" lay-verify="required" placeholder="请输入供应商邮箱" autocomplete="off" class="layui-input">
	            </div>
	        </div>
    	</div>
    	<div class="layui-form-item">
	        <div class="layui-inline">
	            <label class="layui-form-label" >开户行:</label>
	            <div class="layui-input-inline">
	                <input type="text" name="bank" lay-verify="required"  placeholder="请输入供应商开户行" autocomplete="off" class="layui-input">
	            </div>
	        </div>
	        <div class="layui-inline">
	            <label class="layui-form-label" >帐号:</label>
	            <div class="layui-input-inline">
	                <input type="text" name="account" lay-verify="required" placeholder="请输入供应商帐号" autocomplete="off" class="layui-input">
	            </div>
	        </div>
	         <div class="layui-inline">
	            <label class="layui-form-label" >传真:</label>
	            <div class="layui-input-inline">
	                <input type="text" name="fax" lay-verify="required"  placeholder="请输入供应商传真" autocomplete="off" class="layui-input">
	            </div>
	        </div>
    	</div>
    	<div class="layui-form-item">
		    <div class="layui-inline">
		      <label class="layui-form-label">是否有效</label>
		      <div class="layui-input-inline">
		       <input type="radio" name="available"  value="1" title="有效" checked="">
		      <input type="radio" name="available"  value="0" title="无效">
		      </div>
		    </div>
		  </div>
		<div class="layui-form-item" style="text-align: center;">
			<button class="layui-btn" lay-submit="" lay-filter="doSubmit">提交</button>
			<button type="reset" class="layui-btn layui-btn-warm">重置</button>
		</div>
	</form>
</div>
<!-- 添加和修改结束 -->

<script type="text/javascript" src="/resources/layui/layui.js"></script>
</body>
<script type="text/javascript">
    var tableIns;
    layui.use(['form','layer','table'],function(){
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery,
            table = layui.table;
        //供应商列表
        tableIns = table.render({
            elem: '#providerList',
            url : '/provider/loadAllProvider',
            cellMinWidth : 95,
            toolbar: '#tableToolBar',
            page : true,
            height : "full-150",
            id : "providerListTable",
            cols : [ [
                {field: 'id', title: '供应商ID', minWidth:80, align:"center"},
                {field: 'providername', title: '供应商姓名',width:120, minWidth:100, align:"center"},
                {field: 'zip', title: '邮编', minWidth:100,width:120, align:"center"},
                {field: 'address', title: '地址', minWidth:100,width:120, align:"center"},
                {field: 'telephone', title: '公司电话',width:120,  align:'center'},
                {field: 'connectionperson', title: '联系人',width:120, minWidth:100, align:"center"},
                {field: 'phone', title: '联系人电话',width:180, minWidth:100, align:"center"},
                {field: 'bank', title: '开户行',width:120, minWidth:100, align:"center"},
                {field: 'account', title: '帐号',width:180, minWidth:100, align:"center"},
                {field: 'email', title: '邮箱',width:180, minWidth:100, align:"center"},
                {field: 'fax', title: '传真',width:120, minWidth:100, align:"center"},
                {field:'available', width:120, title: '是否有效',align:'center',templet:function(data){
			    	  return data.available==1?'<font color=blue>有效</font>':'<font color=red>无效</font>';
			      }},
                {title: '操作', minWidth:185, templet:'#providerListBar',fixed:"right",align:"center"}
            ] ]
        });

        //查询
        $("#doSearch").click(function(){
            var params=$("#searchForm").serialize();
            table.reload('providerListTable', {
                url: '/provider/loadAllProvider?'+params
            });
        });
        //监听头工具栏事件
        table.on('toolbar(providerList)', function(obj){
            switch(obj.event){
	            case 'add':
	               	toAddProvider();
                	break;
            };
        });

        //打开 添加供应商的弹出层
        var url="";
        var index;
        function toAddProvider(){
            index = layui.layer.open({
                title : "添加供应商",
                type : 1,//页面层
                content : $("#dataFrmContent"),
                skin:'layui-layer-molv',
				area : [ '800px', '550px' ],
				shadeClose:true,//设置是否点击遮罩关闭
				maxmin:true,//设置是否显示最大化和最小化的按钮
				resize:true,//设置是否支持拉伸缩小放大  默认为true
                success : function(layero, index){
                    url="/provider/addProvider"
                }
            })
        }
        
        //修改供应商
        function updateProvider(data){
        	index = layui.layer.open({
                title : "添加供应商",
                type : 1,//页面层
                content : $("#dataFrmContent"),
                skin:'layui-layer-molv',
				area : [ '800px', '550px' ],
				shadeClose:true,//设置是否点击遮罩关闭
				maxmin:true,//设置是否显示最大化和最小化的按钮
				resize:true,//设置是否支持拉伸缩小放大  默认为true
                success : function(layero, index){
                	$("#dataFrm")[0].reset();
                	form.val("dataFrm",data);
                    url="/provider/updateProvider"
                }
            })
        }
        //监听提交
        form.on('submit(doSubmit)', function(data){
            var params=$("#dataFrm").serialize();
            $.post(url,params,function(obj){
            	if(obj.code==200){
    				layer.msg(obj.msg);
    				  //刷新table
                    tableIns.reload();
    				layer.close(index);
    			}else{
    				layer.msg(obj.msg);
    			}
            })
            return false;
        });
        
        //列表操作
        table.on('tool(providerList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;
            if(layEvent === 'update'){ //编辑
                updateProvider(data);//data主当前点击的行
            }else if(layEvent === 'delete'){ //删除
                layer.confirm('确定删【'+data.providername+'】供应商吗？',{icon:3, title:'提示信息'},function(index){
                    $.post("/provider/deleteProvider",{
                        id : data.id  //将需要删除的id作为参数传入
                    },function(data){
                        //刷新table
                        tableIns.reload();
                        //关闭提示框
                        layer.close(index);
                    })
                });
            }
        });
    })
    
</script>
</html>